<template>
  <div>
    <div class="Logout">
      <Logout>退出</Logout>
    </div>
    <h1>更新课程信息</h1>
    <el-input size="medium" v-model="search_cno" placeholder="请输入课程编号"></el-input>
    <el-button @click="search()" icon="el-icon-search" circle></el-button>
    <el-table
      :data="tableData"
      border
      style="width:100%">
      <el-table-column
        fixed
        prop="cno"
        label="课程编号"
        width="150">
      </el-table-column>
      <el-table-column
        prop="cname"
        label="课程名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="cclasstime"
        label="课节数"
        width="120">
      </el-table-column>
      <el-table-column
        prop="ccycle"
        label="上课时间"
        width="120">
      </el-table-column>
      <el-table-column
        prop="camount"
        label="上课费用"
        width="120">
      </el-table-column>
      <el-table-column
        prop="caddress"
        label="上课地址"
        width="120">
      </el-table-column>
      <el-table-column
        prop="tno"
        label="教师编号"
        width="120">
      </el-table-column>
      <el-table-column
        prop="cneed"
        label="课程所需人数"
        width="120">
      </el-table-column>
      <el-table-column
        prop="cjoin"
        label="已报名人数"
        width="120">
      </el-table-column>
      <el-table-column
        label="操作"
        width="150">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">修改</el-button>
          <el-button @click="delCourse(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import Logout from "./Logout";
export default {
  name: "EditCourse",
  components:{Logout},
  created() {
    const  _this = this;
    this.$axios.post(`/EditCourse`).then((res) => {
      console.log(res.data);
      _this.tableData = res.data;
      if (res.data.msg=="更新成功") {
        alert("更新成功")
      } else {
        alert((res.data.msg))
      }
    })
  },
  methods : {
    search() {
      const _this = this;
      this.$axios.get(`/course/list?cno=${this.search_cno}`).then((res) => {
        console.log(res.data);
        _this.tableData = res.data;

      })
    },
    handleClick(row) {
      console.log(row);
      const cno = row.cno;
      //alert(cno);
      this.$router.push({path:'/UpdateCourse',query:{
          cno:cno,
          cname:row.cname,
          cclasstime:row.cclasstime,
          ccycle:row.ccycle,
          camount:row.camount,
          caddress:row.caddress,
          tno:row.tno,
          cneed:row.cneed,
          cjoin:row.cjoin
        }});
    },
    delCourse(row) {
      console.log(row);
      const cno = row.cno;
      const  _this = this;
      this.$axios.get(`/course/delete?cno=${cno}`).then((res) => {
        alert("删除成功");
        this.$axios.get(`/course/list?cno=${_this.search_cno}`).then((res) => {
          console.log(res.data);
          _this.tableData = res.data;
        })
      })

    },
  },
  data () {
    return {
      search_cno:'',
      tableData:'',
    }
  }
}
</script>

<style scoped>

</style>
